%option noyywrap batch

%{
#include "mycomplier.h"
#include "program.h"
#include "common.h"
YY_BUFFER_STATE bp;
FILE *f;
int string_pattern = 0;
%}
%x STRING_P
%%
"int"     {
            char * tmp=copystr(yytext);
            cout<<"int input is "<< tmp<<endl; 
            yylval.TYPE = tmp;
            return TYPE;
            };
"float"     { int a =3;  return TYPE;};
"if"    { cout<<"iffffffff ";return IF;};

[a-z]+    {int b =3;  char * tmp=copystr(yytext);yylval.ID = tmp;cout<<"get id"<<yytext[0]<<endl;return ID;};
[";"]     { return _E;};
"\{"    {cout<<"left block "<<endl; return yytext[0];};
"\}"    {cout<<"right block "<<endl; return yytext[0];};

[ \t]    {};
"="     {cout<<"input is "<< yytext[0]<<endl;return yytext[0];};
["><"]   {char * tmp=copystr(yytext);yylval.COMPARE = tmp;cout<<"get COMPARE"<<yytext[0]<<endl;return COMPARE;};
[\n]+    {return _N;};
[\"]    {
            cout<<"string_pattern "<<string_pattern<<endl;
            if(string_pattern==0)
            {
                string_pattern = 1;
                BEGIN STRING_P;
            }
            else{
                string_pattern = 1;
                BEGIN INITIAL;
            }
            
        };
[1-9]+   {yylval.NUM = atof(yytext);return NUM;};
<STRING_P>[a-z]+ {   
                    cout<<"STRING_P match  "<<yytext<<endl;
                    yylval.STRING = copystr(yytext);
                    return STRING;
                };
<STRING_P>[\"] {string_pattern = 1; BEGIN INITIAL;};
","     { return yytext[0]; };
%%
void lexmain(){
    f = fopen("./test/test.pfl", "r");
    bp = yy_create_buffer(f, YY_BUF_SIZE);
    yy_switch_to_buffer(bp);
}

